/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.jSky.producer;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 *
 * @author Rakev
 */
public class CollectionProducer<F, E, T> implements Producer<F, Collection<T>> {

    private Producer<F, Collection<E>> collectionProducer;
    private Producer<E, T> elementProducer;

    public CollectionProducer(Producer<F, Collection<E>> collectionProducer, Producer<E, T> elementProducer) {
        this.collectionProducer = collectionProducer;
        this.elementProducer = elementProducer;
    }

    @Override
    public Collection<T> produce(F fromObject) {
        Collection<E> tempElements = collectionProducer.produce(fromObject);
        List<T> result = new ArrayList<>(tempElements.size());
        for (E tempElement : tempElements) {
            result.add(elementProducer.produce(tempElement));
        }
        return result;
    }
}
